<template>
	<view class="page">
		<u-navbar :autoBack="true" placeholder bgColor="transparent" leftIconSize="40rpx">
			<view slot="center" style="font-size: 40rpx; font-weight: 500">会员详情</view>
		</u-navbar>

		<view class="main-content">
			<view class="member-card">
				<view class="member-header">
					<view class="member-info">
						<text class="member-name">{{ userInfo.nickname }}</text>
						<text class="member-id">ID:{{ userInfo.id }}</text>
						<text class="member-phone">{{ userInfo.tel }}</text>
					</view>
					<view class="qrcode-box"@tap="handleViewQrcode()">
						<image src="/static/img/agent/ercode.png" mode=""></image>
					</view>
				</view>

				<view class="stats-grid">
					<view class="stats-item">
						<text class="stats-label">销售总额</text>
						<text class="stats-value primary">{{ userInfo.sales_amount }}</text>
					</view>
					<view class="stats-item">
						<text class="stats-label">订单总数</text>
						<text class="stats-value">{{ userInfo.order_count }}</text>
					</view>
					<view class="stats-item">
						<text class="stats-label">当前月化</text>
						<text class="stats-value">{{ userInfo.month_rate }}</text>
					</view>
					<view class="stats-item">
						<text class="stats-label">当前余额</text>
						<text class="stats-value">{{ userInfo.money }}</text>
					</view>
				</view>

				<view class="action-grid" @tap="toWithdraw()">
					<view class="action-item">
						<text class="action-text">申请提现</text>
					</view>
				</view>
			</view>

			<view class="function">
				<view class="functionData">
					<view class="functionDataItem" v-for="(item, index) in menuItems" :key="index"
						@click="handleMenuClick(item)">
						<view class="itemCenter">
							<view>
								<image :src="item.icon" mode=""></image>
							</view>
							<view class="itemLabel">
								{{ item.label }}
							</view>
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	var app = getApp();
	export default {
		data() {
			return {
				uid:0,
				userInfo: {
					nickname: "王重阳",
					id: "4352",
					tel: "13212345678",
					sales_amount: "45678.00",
					order_count: "56",
					month_rate: "1.2%",
					balance: "30000",
				},

				menuItems: [{
						label: '余额明细',
						icon: '/static/img/agent/balance.png',
						url: '/pages/money/moneylog'
					},
					{
						label: '他的订单',
						icon: '/static/img/agent/order.png',
						url: '/pagesExt/order/orderlist'
					},
					{
						label: '他的提现',
						icon: '/static/img/agent/withdraw.png',
						url: '/activity/commission/commissionlog'
					},
					{
						label: '他的直推',
						icon: '/static/img/agent/team.png',
						url: '/activity/commission/myteam'
					},
					{
						label: '他的佣金',
						icon: '/static/img/agent/commission.png',
						url: '/activity/commission/index'
					},
					{
						label: '他的分销',
						icon: '/static/img/agent/distribution.png',
						url: '/activity/commission/downorder'
					},
					{
						label: '他的分红',
						icon: '/static/img/agent/bonus.png',
						url: '/activity/commission/fhlog'
					}
				],
			};
		},
		onLoad(options){
			if(options.id){
				this.uid = options.id;
				this.loadData(this.uid)
			}
		},
		methods: {
			handleViewQrcode(item) {
				uni.navigateTo({
					url:'/activity/commission/poster?childid='+this.uid
				})
				// this.currentMember = item;
				// this.qrcodeModal = true;
			},
			toWithdraw(){
				uni.navigateTo({
					url:'/activity/commission/withdraw?childid='+this.uid
				})
			},
			loadData(uid) {
				let that = this
				app.post("ApiMy/getChild", {
					childid:uid
				}, function(data) {
					if (data.status != 1) {
						app.alert(data.msg);
						return;
					} else {
						that.userInfo = data.data
						console.log(that.userInfo)
					}
				});
			},
			touser() {
				uni.navigateTo({
					url: '/pages/agent/list'
				})
			},
			handleMenuClick(item) {
				if (!item.url) {
					return uni.showToast({
						title: '功能开发中',
						icon: 'none'
					});
				}

				try {
					uni.navigateTo({
						url: item.url+'?childid='+this.uid,
						fail: (err) => {
							console.error('页面跳转失败:', err);
							uni.showToast({
								title: '页面跳转失败',
								icon: 'none'
							});
						}
					});
				} catch (error) {
					console.error('导航异常:', error);
					uni.showToast({
						title: '系统异常',
						icon: 'none'
					});
				}
			}
		}
	};
</script>

<style lang="less" scoped>
	.main-content {
		flex: 1;
		padding: 20rpx 32rpx 0;
		overflow-y: auto;
	}

	.member-card {
		background: #ffffff;
		border-radius: 24rpx;
		padding: 32rpx 32rpx 0;
		box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
		margin-bottom: 30rpx;

		.member-header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 30rpx;
		}

		.member-info {
			display: flex;
			align-items: center;
		}

		.member-name {
			font-weight: 500;
			font-size: 35rpx;
			color: #000000;
			margin-right: 29rpx;
		}

		.member-id,
		.member-phone {
			font-size: 26rpx;
			color: #999999;
			margin-right: 32rpx;
			align-self: flex-end;
		}

		.qrcode-box {
			width: 35rpx;
			height: 35rpx;
			display: flex;
			align-items: center;
			justify-content: center;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.stats-grid {
			display: grid;
			grid-template-columns: repeat(4, 1fr);
			gap: 32rpx;
			margin-bottom: 25rpx;
		}

		.stats-item {
			text-align: left;
			padding-left: 10rpx;
		}

		.stats-value {
			font-weight: 500;
			font-size: 26rpx;
			color: #000000;
		}

		.stats-value.primary {
			color: #007aff;
		}

		.stats-label {
			font-size: 26rpx;
			color: #939393;
			display: block;
			font-weight: 500;
			margin-bottom: 8rpx;
		}

		.action-grid {
			display: flex;
			justify-content: flex-end;
			border-top: 1px solid #f4f4f4;
			padding: 16rpx 0;
		}

		.action-item {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding: 0 14rpx;
		}

		.action-text {
			font-size: 26rpx;
			color: #0086ef;
		}
	}

	.function {
		padding: 25rpx 10rpx;
		margin: auto;
		background-color: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;

		.functionData {
			display: flex;
			flex-wrap: wrap;

			.functionDataItem {
				margin: 18rpx 0;
				width: 25%;
				height: 132rpx;
				border-radius: 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;

				.itemCenter {
					text-align: center;

					image {
						width: 83rpx;
						height: 83rpx;
					}

					.itemLabel {
						margin-top: 12rpx;
					}
				}
			}
		}
	}
</style>
